using System;
using System.Net;

using Pegasus.Runtime.Serialization;

namespace Pegasus.ServiceModel
{
	/// <summary>
	/// Describes the information about a node.
	/// </summary>
	public class NodeInfo
	{
		// Local Instance Values
		private string m_name;
		private string m_machineName;
		private IPAddress m_ipAddress;
		private object m_tag;

		/// <summary>
		/// Initializes a new instance of the <see cref="NodeInfo"/> class.
		/// </summary>
		/// <param name="nodeInfo">The node info.</param>
		internal NodeInfo( NodeData nodeInfo )
		{
			m_name = nodeInfo.Name;
			m_machineName = nodeInfo.MachineName;
			m_ipAddress = nodeInfo.IPAddress;

			if( !string.IsNullOrEmpty( nodeInfo.Tag ) )
			{
				m_tag = SerializationHelper.XmlToObject( nodeInfo.Tag );
			}
		}

		/// <summary>
		/// Gets the name the node.
		/// </summary>
		/// <value>The name.</value>
		public string Name
		{
			get
			{
				return m_name;
			}
		}

		/// <summary>
		/// Gets the name of the machine the node is running on.
		/// </summary>
		/// <value>The name of the machine.</value>
		/// <remarks>
		/// You can have multiple applications (nodes) running on the same system.
		/// </remarks>
		public string MachineName
		{
			get
			{
				return m_machineName;
			}
		}

		/// <summary>
		/// Gets the IP address of the system the node is running on.
		/// </summary>
		/// <value>The IP address.</value>
		public IPAddress IPAddress
		{
			get
			{
				return m_ipAddress;
			}
		}

		/// <summary>
		/// Gets the user defined tag object that we attached by the source node.
		/// </summary>
		/// <value>The node tag object.</value>
		public object NodeTag
		{
			get
			{
				return m_tag;
			}
		}

		/// <summary>
		/// Returns a <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
		/// </summary>
		/// <returns>
		/// A <see cref="T:System.String"></see> that represents the current <see cref="T:System.Object"></see>.
		/// </returns>
		public override string ToString()
		{
			return m_name;
		}
	}
}
